<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>10点击隐藏文字</title>
    <style>
        input,button{
            padding: 0;
            border: 0 none;
        }
        .search{
            width:258px;
            height: 40px;
            background-color: pink;
            margin: 100px auto;
        }
        .search input{
            width: 208px;
            height: 40px;
            background: url(images/left.jpg) no-repeat;
            outline-style: none;
            padding-left: 8px;
            color: #ccc;
            float: left;
        }
        .search button{
            width: 42px;
            height: 40px;
            float: left;
            background: url(images/right.jpg) no-repeat;
            cursor: pointer;
        }
    </style>
    <script>
        window.onload = function () {
            var txt = document.getElementById("name");
            txt.onfocus = function(){
                //清空
                this.value = "";
            }
            //失去焦点判断输入内容
            txt.onblur = function(){
                if(this.value==""){
                    this.value="请输入...";
                }
            }
            document.getElementsByTagName("button")[0].onclick = function(){
                if(txt.value=="" || txt.value=="请输入..."){
                    txt.value="请输入...";
                    alert("请输入内容");
                    return;  //终止代码继续向下执行
                }
                alert("正在搜索，请稍后");
            }
        }
    </script>
</head>
<body>
<div class="search">
    <input type="text" value="请输入..." id="name">
    <button></button>
</div>
</body>
</html>